package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.StApiInfo;
import com.ruoyi.system.service.IStApiInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * API信息Controller
 * 
 * @author wmao
 * @date 2024-07-20
 */
@Controller
@RequestMapping("/system/stapi")
public class StApiInfoController extends BaseController
{
    private String prefix = "system/stapi";

    @Autowired
    private IStApiInfoService stApiInfoService;

    @RequiresPermissions("system:stapi:view")
    @GetMapping()
    public String stapi()
    {
        return prefix + "/stapi";
    }

    /**
     * 查询API信息列表
     */
    @RequiresPermissions("system:stapi:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StApiInfo stApiInfo)
    {
        startPage();
        List<StApiInfo> list = stApiInfoService.selectStApiInfoList(stApiInfo);
        return getDataTable(list);
    }

    /**
     * 导出API信息列表
     */
    @RequiresPermissions("system:stapi:export")
    @Log(title = "API信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StApiInfo stApiInfo)
    {
        List<StApiInfo> list = stApiInfoService.selectStApiInfoList(stApiInfo);
        ExcelUtil<StApiInfo> util = new ExcelUtil<StApiInfo>(StApiInfo.class);
        return util.exportExcel(list, "API信息数据");
    }

    /**
     * 新增API信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存API信息
     */
    @RequiresPermissions("system:stapi:add")
    @Log(title = "API信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StApiInfo stApiInfo)
    {
        return toAjax(stApiInfoService.insertStApiInfo(stApiInfo));
    }

    /**
     * 修改API信息
     */
    @RequiresPermissions("system:stapi:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        StApiInfo stApiInfo = stApiInfoService.selectStApiInfoById(id);
        mmap.put("stApiInfo", stApiInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存API信息
     */
    @RequiresPermissions("system:stapi:edit")
    @Log(title = "API信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StApiInfo stApiInfo)
    {
        return toAjax(stApiInfoService.updateStApiInfo(stApiInfo));
    }

    /**
     * 删除API信息
     */
    @RequiresPermissions("system:stapi:remove")
    @Log(title = "API信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(stApiInfoService.deleteStApiInfoByIds(ids));
    }
}
